<?php

require "include/bittorrent.php";
dbconn();

//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: text/xml; charset=utf-8");
$id = 0 + $_GET['torrentid'];
if (isset($CURUSER)) {
	$row = mysql_fetch_array(sql_query("SELECT seedtime, uploaded FROM snatched WHERE torrentid = $id AND userid = $CURUSER[id]")); //认领时用户对该种的做种时间和上传量
	$checktorrentnum = mysql_num_rows(sql_query("SELECT id FROM claim WHERE torrentid = $id AND userid = $CURUSER[id]")); //检查用户是否认领该种子
	$checknum = mysql_num_rows(sql_query("SELECT id FROM claim WHERE torrentid = $id")); //检查认领该种子的人数
	$checkusernum = mysql_num_rows(sql_query("SELECT id FROM claim WHERE userid = $CURUSER[id]")); //检查该用户认领数量
	if ($checknum < $claimmaxnum) {
		if ($checkusernum < $claimnum) {
			if ($checktorrentnum != 1) {
				sql_query("INSERT INTO claim (torrentid, userid, seedtime, uploaded, added) VALUE ('$id', '$CURUSER[id]', '" . (0 + $row['seedtime']) . "', '" . (0 + $row['uploaded']) . "', '" . date("Y-m-d", time()) . "')") or sqlerr(__FILE__, __LINE__);
				echo "claim";
			}
		}
	} else {
		return false;
	}
} else {
	return false;
}
